#!/bin/sh
#
# This is to be executed by xinit as well as by display managers.
# It takes a program and its arguments, which it is supposed to exec
# once it's done setting up its own stuff.
#
# The base script does not do much. It only sources files in Xsession.d.
#
# Copyright 2022 q66 <q66@chimera-linux.org>
#

ERRBASE="${XDG_DATA_HOME:-$HOME/.local/share}/xorg"
ERRFILE="${ERRBASE}/xsession-errors"

if (umask 077 && mkdir -p "$ERRBASE" && touch "$ERRFILE") 2> /dev/null && \
  [ -w "$ERRFILE" ] && [ ! -L "$ERRFILE" ]; then
    chmod 600 "$ERRFILE"
    # conditionally redirect if we have access
    exec >>"$ERRFILE" 2>&1
fi

for f in /etc/X11/Xsession.d/*; do
    [ ! -x "$f" ] && continue
    . "$f"
done

unset f

exec "$@"
